from selenium.webdriver.common.by import By
from pages.base_page import Page


class VisitorSSOPage(Page):
    ele_page_title = (By.XPATH, u"//h3[text()='Visitor Single Sign-On (SSO)']")
    ele_switch_button = (By.XPATH, u"//span[@data-tag='featureSwitch']")
    ele_is_enable_feature_switch = (By.XPATH, u"//span[@data-tag='featureSwitch']/span/div")
    ele_page_feature_introduction_title = (By.XPATH, u"//h3[text()='Feature Introduction']")
    # ele_switch_button2 = (By.XPATH, u"//*[@id='page-visitorSsoConfig']/div[1]/div/div/span/span[1]/span/div")
    ele_download_spm = (By.XPATH, u"//span[text()='Download Service Provider Metadata']")
    ele_sign_in_url = (By.XPATH, u"//input[@name='signInUrl']")
    ele_artifact_resolution_service_url = (By.XPATH, u"//input[@name='artifactResolutionServiceUrl']")
    ele_log_out_url = (By.XPATH, u"//input[@name='logoutUrl']")
    ele_saml_certificate = (By.XPATH, u"//textarea[@name='samlCertificate']")
    ele_sso_data_mapping_table = (By.XPATH, u"//div[@data-formfield='visitorSsoFieldMappings']")
    ele_visitor_sso_table = (By.XPATH, u"//div[@data-formfield='visitorSsos']")
    ele_button_save = (By.XPATH, u"//span[text()='Save']")
    ele_button_unlock_this_feature = (By.XPATH, u"//span[text()='Unlock This Feature']")

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def visitor_sso_page_eles_check_with_sso_feature(self):
        self.find_element(*self.ele_page_title).is_enabled()
        self.find_element(*self.ele_switch_button).is_enabled()
        self.find_element(*self.ele_is_enable_feature_switch).is_enabled()
        self.find_element(*self.ele_download_spm).is_enabled()
        self.find_element(*self.ele_sign_in_url).is_enabled()
        self.find_element(*self.ele_artifact_resolution_service_url).is_enabled()
        self.find_element(*self.ele_log_out_url).is_enabled()
        self.find_element(*self.ele_saml_certificate).is_enabled()
        self.find_element(*self.ele_sso_data_mapping_table).is_enabled()
        self.find_element(*self.ele_visitor_sso_table).is_enabled()
        self.find_element(*self.ele_button_save).is_enabled()

    def enable_switch(self):
        fs = self.find_element(*self.ele_is_enable_feature_switch)
        if fs.text == 'OFF':
            self.click(self.ele_switch_button)
        else:
            pass

    def save_config(self):
        self.click(self.ele_button_save)

    def visitor_sso_page_eles_check_without_sso_feature(self):
        self.find_element(*self.ele_page_title).is_enabled()
        self.find_element(*self.ele_page_feature_introduction_title).is_enabled()
        self.find_element(*self.ele_button_unlock_this_feature).is_enabled()
